package com.qifei.xmlg_backend.service.impl;

import com.qifei.xmlg_backend.entity.Job;
import com.qifei.xmlg_backend.entity.JobCount;
import com.qifei.xmlg_backend.mapper.EmpMapper;
import com.qifei.xmlg_backend.mapper.JobMapper;
import com.qifei.xmlg_backend.service.IJobService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author job
 * @since 2025-06-16
 */
@Service
public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements IJobService {
    private final EmpMapper empMapper;

    public JobServiceImpl(EmpMapper empMapper) {
        this.empMapper = empMapper;
    }

    @Override
    public JobCount getCountList() {
        List<Job> list = this.list();

        if (list != null && !list.isEmpty()){
            JobCount jobCount = new JobCount();

            List<String> jobNames = list.stream()
                    .map(Job::getName)
                    .collect(Collectors.toUnmodifiableList());
            jobCount.setJobNames(jobNames);

            List<Integer> jobCounts = list.stream()
                    .map(job -> empMapper.selectCountByJobId(job.getId()))
                    .collect(Collectors.toUnmodifiableList());
            jobCount.setJobCounts(jobCounts);

            return jobCount;
        }
        return null;
    }
}
